package ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.io.IOException;
import java.util.UUID;

import application.App;
import base.BaseBean;
import base.activity.BaseNetActivity;
import student.andlei.com.student.R;
import view.LinePathView;

public class AddWacomActivity extends BaseNetActivity{
    private ImageView check_pen,
            check_rubber,
            img_clean;
    private LinearLayout layout_pen,
            layout_rubber;
    private LinePathView paletteView;
    private Button bt_save;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setBaseBack(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        setTitle("手写板");
    }

    @Override
    public void success(String action, BaseBean baseBean) {

    }

    @Override
    public void error(String action, Throwable e) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_addwacom;
    }

    @Override
    protected void findViews() {
        check_pen = getView(R.id.check_pen);
        check_rubber = getView(R.id.check_rubber);
        layout_pen = getView(R.id.layout_pen);
        layout_rubber = getView(R.id.layout_rubber);
        paletteView = getView(R.id.plt_wacom);
        img_clean = getView(R.id.img_clean);
        bt_save = getView(R.id.bt_save);
    }

    @Override
    protected void formatViews() {
        img_clean.setOnClickListener(this);
        bt_save.setOnClickListener(this);
        check_pen.setOnClickListener(this);
        check_rubber.setOnClickListener(this);
    }

    @Override
    protected void formatData() {

    }

    @Override
    protected void getBundle(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //画笔
            case R.id.check_pen:
                //toast("画笔");
                //paletteView.setMode(PaletteView.Mode.DRAW);
                paletteView.setPenColor(Color.BLACK);
                paletteView.setPaintWidth(5);
                layout_pen.setBackgroundResource(R.color.check_color);
                layout_rubber.setBackgroundResource(R.color.uncheck_color);
                break;
            //橡皮
            case R.id.check_rubber:
                //toast("橡皮");
                //paletteView.setMode(PaletteView.Mode.ERASER);
                paletteView.setPenColor(Color.WHITE);
                paletteView.setPaintWidth(50);
                layout_rubber.setBackgroundResource(R.color.check_color);
                layout_pen.setBackgroundResource(R.color.uncheck_color);
                break;
            //清除手写板按钮
            case R.id.img_clean:
                //toast("清除手写板按钮");
                paletteView.clear();
                break;
            //保存按钮
            case R.id.bt_save:

                String path =App.getAppCacheDir(context)+ UUID.randomUUID().toString()+ ".jpg";
                try {
                    paletteView.save(path);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                Intent intent = new Intent();
                intent.putExtra("filename",path);
                setResult(0,intent);
                finish();
                break;
        }
    }
}
